package cn.com.blueInfo.bpm.template.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.template.request.ParallelBranchDTO;
import cn.com.blueInfo.bpm.template.response.ParallelBranchVO;
import cn.com.blueInfo.bpm.template.service.ParallelBranchService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 并行分支表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:41:15
 */
@Tag(name = "并行分支 接口")
@RestController
@RequestMapping("/template/parallelBranch")
public class ParallelBranchController extends BaseController {

    @Autowired
    private ParallelBranchService parallelBranchService;

    /**
     * 新建并行分支
     * @param parallelBranchDTO 并行分支参数
     * @return ResultInfo
     */
    @Operation(summary = "新增并行分支")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createParallelBranch(
            @Validated({Create.class, Default.class}) @RequestBody ParallelBranchDTO parallelBranchDTO) {
        return parallelBranchService.addParallelBranch(parallelBranchDTO);
    }

    /**
     * 批量新建并行分支
     * @param parallelBranchDTOList 并行分支参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建并行分支")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateParallelBranch(
            @Validated({Create.class, Default.class}) @RequestBody List<ParallelBranchDTO> parallelBranchDTOList) {
        return parallelBranchService.batchAddParallelBranch(parallelBranchDTOList);
    }

    /**
     * 根据ID删除并行分支
     * @param parallelBranchId 并行分支ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除并行分支")
    @DeleteMapping("/removeInfo/{parallelBranchId}")
    public ResultInfo<Integer> deleteParallelBranchById(
            @Parameter(name = "ID") @PathVariable Long parallelBranchId) {
        return parallelBranchService.removeParallelBranch(parallelBranchId);
    }

    /**
     * 批量根据ID删除并行分支
     * @param parallelBranchIdList 并行分支ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除并行分支")
    @DeleteMapping("/removeInfoList/{parallelBranchIdList}")
    public ResultInfo<Integer> batchDeleteParallelBranchById(
            @Parameter(name = "ID") @PathVariable List<Long> parallelBranchIdList) {
        return parallelBranchService.batchRemoveParallelBranch(parallelBranchIdList);
    }

    /**
     * 根据ID全量更新并行分支
     * @param parallelBranchId 并行分支ID
     * @param parallelBranchDTO 并行分支参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新并行分支")
    @PutMapping("/modifyInfo/{parallelBranchId}")
    public ResultInfo<Integer> updateParallelBranchFull(
            @Parameter(name = "ID") @PathVariable Long parallelBranchId,
            @Validated({Update.class, Default.class}) @RequestBody ParallelBranchDTO parallelBranchDTO) {
        validateUpdateId(parallelBranchId, parallelBranchDTO.getId());
        return parallelBranchService.modifyParallelBranch(parallelBranchDTO);
    }

    /**
     * 根据ID部分更新并行分支
     * @param parallelBranchId 并行分支ID
     * @param parallelBranchUpdatePartialDTO 并行分支参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新并行分支")
    @PatchMapping("/modifyPartialInfo/{parallelBranchId}")
    public ResultInfo<Integer> updateParallelBranchPartial(
            @Parameter(name = "ID") @PathVariable Long parallelBranchId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            ParallelBranchDTO.UpdatePartialDTO parallelBranchUpdatePartialDTO) {
        validateUpdateId(parallelBranchId, parallelBranchUpdatePartialDTO.getId());
        return parallelBranchService.modifyParallelBranchPartial(parallelBranchUpdatePartialDTO);
    }

    /**
     * 根据ID查询并行分支
     * @param parallelBranchId 并行分支ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询并行分支")
    @GetMapping("/getInfo/{parallelBranchId}")
    public ResultInfo<ParallelBranchVO> getParallelBranchById(
            @Parameter(name = "ID") @PathVariable Long parallelBranchId) {
        return parallelBranchService.queryParallelBranchById(parallelBranchId);
    }

    /**
     * 分页查询并行分支
     * @param parallelBranchQueryDTO 并行分支参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询并行分支")
    @GetMapping("/getInfos")
    public ResultInfo<Page<ParallelBranchVO>> getParallelBranchPage(
            @Validated ParallelBranchDTO.QueryDTO parallelBranchQueryDTO) {
        return parallelBranchService.queryParallelBranchPage(parallelBranchQueryDTO);
    }

    /**
     * 根据条件查询并行分支
     * @param parallelBranchQueryDTO 并行分支参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询并行分支")
    @GetMapping("/getInfoList")
    public ResultInfo<List<ParallelBranchVO>> getParallelBranchList(
            @Validated ParallelBranchDTO.QueryDTO parallelBranchQueryDTO) {
        return parallelBranchService.queryParallelBranchList(parallelBranchQueryDTO);
    }

}
